#ifndef FLASH_EEPROM_H
#define FLASH_EEPROM_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif


#define FLASH_EEPROM_SECTOR_SIZE 16 //(4 * 1024)
#define FLASH_EEPROM_BLOCK_SIZE (16*16) //(16 * FLASH_EEPROM_SECTOR_SIZE)

#define FLAsh_EEPROM_MAX_VARIABLES 50  // this should be less then (FLASH_EEPROM_SECTOR_SIZE / 12)

#define FLASH_EEPROM_INVALID_ID (0xffffffff)
#define FLASH_EEPROM_RESET_VAL (0xff)
#define FLASh_EEPROM_MAGIC_ID1 (0xaa554477)
#define FLASh_EEPROM_MAGIC_ID2 (0x55aa7744)

#define FLASH_EEPROM_ERROR (-1)
#define FLASH_EEPROM_ERROR_NO_MEM (-2)
#define FLASH_EEPROM_ERROR_BAD_ID (-3)
#define FLASH_EEPROM_ERROR_BAD_ADDR (-4)
#define FLASH_EEPROM_ERROR_TOO_MUSH_VAR (-5)

uint32_t flash_eeprom_makeid(const char *name);
/*
 * @base_addr [in] flash block start addr
 * @n_blocks [in] blocks num
 * @note 
 */
int flash_eeprom_init(uint32_t base_addr, uint8_t n_blocks);
/*
* @flag [in] 1 -- flush flash in force, move data
*/
int flash_eeprom_flush(uint8_t flag);
/*
* @id [in]
* @data [in]
* @len [in]
* @note data length must smaller than one sector size
*/
int flash_eeprom_write(uint32_t id, uint8_t *data, uint32_t len);
int flash_eeprom_read(uint32_t id, uint8_t *buff, uint32_t len);
int flash_eeprom_erase_all();

#ifdef __cplusplus
}
#endif
    
#endif